package com.fm.text.searcher;

import com.fm.base.struct.BasicHashMap;
import com.fm.base.struct.BasicHashSet;
import com.fm.base.util.Pair;

import java.util.Iterator;

public class State {
	BasicHashMap<Character, State> links;
	State failure;
	BasicHashSet<State> beFailureTo;
	String word;
	Object data;

	State() {
		this(null);
	}

	private State(String word) {
		this(word, null);
	}

	private State(String word, Object data) {
		this.word = word;
		this.data = data;
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append('{');
		if (links != null) {
			Iterator<Pair<Character, State>> iterator = links.iterator();
			while (iterator.hasNext()) {
				builder.append(iterator.next().left);
				if (iterator.hasNext()) {
					builder.append(',');
				}
			}
		}
		builder.append('}');
		return builder.toString();
	}
}
